package ru.spb.osll.myfit.server;

import java.util.Comparator;

public class FixtureNameComparator implements Comparator<String> {
  
  private static final String POSSIBLE_POSTFIX = "fixture";
  
  @Override
  public int compare(String s1, String s2) {
    return prepareString(s1).compareToIgnoreCase(prepareString(s2));
  }
  
  private String prepareString(String str)  {
    StringBuilder sb = new StringBuilder(str);
    int index;
    
    if ((index = sb.lastIndexOf(POSSIBLE_POSTFIX)) != -1)
      sb.replace(index, index  + POSSIBLE_POSTFIX.length(),"");
    
    return sb.toString().trim();
  }
}
